package com.ytjj.qmyx.mall.controller;

import com.alibaba.fastjson.JSONObject;
import com.ytjj.common.api.CommonPage;
import com.ytjj.common.api.CommonResult;
import com.ytjj.qmyx.mall.model.dto.HeadImgsAndNumDto;
import com.ytjj.qmyx.mall.model.dto.ProductSubjectPlateDto;
import com.ytjj.qmyx.mall.model.dto.SubjectPlateProductDto;
import com.ytjj.qmyx.mall.model.dto.SubjectsDto;
import com.ytjj.qmyx.mall.service.SubjectsService;
import com.ytjj.qmyx.users.mapper.UsersInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.*;

/**
 *
 * 
 * @description:
 */
@RestController
@RequestMapping("/subjectsController")
public class SubjectsController {

    @Autowired
    private SubjectsService subjectsService;
    @Resource
    private UsersInfoMapper usersInfoMapper;



    /**
    * 获取专题信息（包括专题-专题板块-板块下的商品）
    * @param id:
    * @returns: com.ytjj.common.api.CommonResult
    * 
    */
    @GetMapping("/getSubjectsInfo/{id}")
    public CommonResult getSubjectsInfo(@PathVariable Integer id){
        SubjectsDto subjectsById = subjectsService.getSubjectsById(id);
        return CommonResult.success(subjectsById);
    }


    /**
    * 获得板块下的商品
    * @param id:
    * @param pageNum:
    * @param pageSize:
    * @returns: com.ytjj.common.api.CommonResult
    * 
    */
    @GetMapping("/getProducts")
    public CommonResult getProducts(Integer id,Integer pageNum,Integer pageSize){
        CommonPage<ProductSubjectPlateDto> productByPlateId = subjectsService.getProductByPlateId(id, pageNum, pageSize);
        return CommonResult.success(productByPlateId);
    }

    /**
     * 获得专题下的商品
     * @param id: 专题id
     * @param pageNum:
     * @param pageSize:
     * @returns: com.ytjj.common.api.CommonResult
     * 
     */
    @GetMapping("/getSubjectProducts")
    public CommonResult getSubjectProducts(@RequestParam(required = false) Integer id,
                                           @RequestParam Integer pageNum,
                                           @RequestParam Integer pageSize){
        CommonPage<SubjectPlateProductDto> productByPlateId = subjectsService.getSubjectProducts(id, pageNum, pageSize);
        return CommonResult.success(productByPlateId);
    }

    @GetMapping("/getHeadImgsAndNum")
    public CommonResult getHeadImgsAndNum(){
        Integer v = new Random().nextInt(500) + 2500;
        List<String> headImgs = usersInfoMapper.selectHeadImgs();
        HeadImgsAndNumDto headImgsAndNumDto = new HeadImgsAndNumDto();
        headImgsAndNumDto.setNum(v);
        headImgsAndNumDto.setHeadImgs(headImgs);
        return CommonResult.success(headImgsAndNumDto);
    }

    public static void main(String[] args) {
        Integer v = new Random().nextInt(1000) + 2500;
        System.out.println(v);
    }


    /**
    * 获得活动商品
    * @param id:
    * @param activeType:
    * @returns: com.ytjj.common.api.CommonResult
    * 
    */
    @GetMapping("/getActivitiesGoods")
    public CommonResult getActivitiesGoods(Integer id,String activeType){
        return CommonResult.success(subjectsService.getProductBySubjectId(id,activeType));
    }

    /**
     * 获取专题 - 新人专享使用
     * @param id
     * @return
     */
    @GetMapping("/newGetSubjectsInfo/{id}")
    public CommonResult newGetSubjectsInfo(@PathVariable Integer id){
        SubjectsDto subjectsById = subjectsService.newGetSubjectsById(id);
        return CommonResult.success(subjectsById);
    }
}
